// TabBarItem则只需把其中css和结构搭好即可
<template>
  <div class="tab-bar-item ignore" @click="itemClick">
    <!-- 因为这样item中的内容就是写死的，所以也需要用slot插槽 -->
    <div v-if="!isActive"><slot name="item-icon"></slot></div>
    <div v-else><slot name="item-icon-active"></slot></div>
    <div :style="activeStyle"><slot name="item-text"></slot></div>
    <!-- <img src="../../assets/img/tabbar/home.svg" alt="">
    <div>首页</div> -->
  </div>
</template>

<script>
export default {
  props: {
    //通过props传值，动态获取路径
    path: String,
    activeColor: {
      type: String,
      default: "#dd6572",
    },
  },
  data() {
    return {
      // isActive: true //添加isActive来改变图片
    };
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.path) !== -1; //查找当前字符串中路由的路径是否是props传值的path
    },
    activeStyle() {
      return this.isActive ? { color: this.activeColor } : {};
    },
  },
  methods: {
    itemClick() {
      this.$router.push(this.path);
    },
  },
};
</script>

<style>
.tab-bar-item {
  height: 49px;
  font-size: 10px;
}
.tab-bar-item img {
  margin-top: 3px;
  margin-left: 1px;
  width: 20px;
  height: 20px;
  vertical-align: middle;
}

/* .active {
      color: #dd6572;
    } */
</style>
